<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <script>
    function arr(N, K, W) {
      let dp = new Array(K + W).fill(0)
      //dp[x] 表示手牌为x时获胜的概率
      let s = 0
      for (let i = K; i < K + W; i++) {
        //填（k~k+w-1），此时已经无抽牌机会，只需比较是否小于等于N
        if (i <= N) {
          dp[i] = 1
        } else {
          dp[i] = 0
        }
        s += dp[i]
      }
      for (let i = K - 1; i >= 0; i--) {
        //填（1~k-1），s即为dp[x+1]+dp[x+2]+dp[x+3]...+dp[x+w],所以dp[x]为s/w     
        dp[i] = s / W
        s = s + dp[i] - dp[i + W]
      }
      return dp[0]
    };
    console.log(arr(10, 1, 10));
  </script>
</body>

</html>